﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace BoekenUsb2.Model.DatabaseRepositories
{
    public abstract partial class DatabaseRepository
    {
        /*********/
        /* Groep */
        /*********/

        public DataTable Groep_GetData()
        {
            return defaultExecuteReaderDataTable(CommandType.Text, "SELECT groepID, groepCode, jaar, omschrijving, raming, opmerking FROM Groep");
        }

        public DataTable Groep_GetBoekGebruiktInGroep(int boekID)
        {
            DataTable dt = new DataTable();
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(1);
                dbManager.AddParameters(0, "@boekID", boekID);
                dbManager.ExecuteReader(CommandType.Text, "SELECT groepID, groepCode, jaar, omschrijving, raming, opmerking FROM Groep WHERE (groepCode IN (SELECT groepCode FROM Boeklijst WHERE (boeklijstID IN (SELECT boeklijstID FROM BoeklijstItem WHERE (boekID = @boekID)))))");
                dt.Load(dbManager.DataReader);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                dbManager.Dispose();
            }
            return dt;
        }

        public bool Groep_Truncate()
        {
            bool succeed = false;
            try
            {
                dbManager.Open();
                dbManager.ExecuteNonQuery(CommandType.Text, "TRUNCATE TABLE Groep");
                succeed = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                dbManager.Dispose();
            }
            return succeed;
        }

    }
}
